define(['jquery','pages/index/model','pages/index/goodsList','pages/index/refresh','pages/index/charts'],function($,cfg,mySwiper,refresh,charts){
    var ct,
        isInit=false,
        swiper,
        data,
        updateSwiper=function(){
        	var i=0,
        	    html='',
        	    rows=cfg.goods_obj[cfg.groupid];
 
        	swiper.removeAllSlides();
        	cfg.code=0;
        	if(rows){
	        	for(var k in rows){       		
	        		data=rows[k];
	        		if(data){
		        		html=['<div class="swiper-slide" index="',i,'" goodscode="',data.goodscode,'" ><a href="javascript:void(0);"><p class="title">',data.goodsname,'</p><p><span>',data.goodsprice,'</span>元/手</p><p>波动盈亏：',data.agreeunit/Math.pow(10,data.mindecimal),'元</p></a> </div>'].join('');       		
		        	    swiper.appendSlide(html);
		        	    if(!i)cfg.code=data.goodscode;
	        		}
	        	    i++;
	        	}
	        	if(swiper.slides.length){
	        		swiper.slideTo(swiper.slides.length>1?1:0);
	        	}
        	}
        };
      
    
    return {
       init:function(){
       	  if(!isInit){
       	    ct=$('#tabs'),
       	    swiper=mySwiper.getSwiper();
       	   	ct.on('click','a',function(){
		    	var $this=$(this),
		    	    $item=$this.parent('div'),
		    	    goodsInfo=$item.attr('goodsInfo').split('|');
		    	 
			 	cfg.code=goodsInfo[0];
		        cfg.groupid=goodsInfo[1];
		    
		        refresh.updateRefreshUI(true);
		        refresh.updateOpenClose();
		        charts.doSwitch(charts.curType());
		        
		        updateSwiper();
		        
		        ct.find('a.selected').removeClass('selected');
		        $this.addClass('selected');
		    })
		    isInit=true;
       	  }
       }
    }
})